package com.eqdd.yiqidian.utils;

import android.app.Activity;
import android.content.Intent;

import com.eqdd.yiqidian.ui.PicPreviewActivity;
import com.eqdd.yiqidian.ui.mine.setting.AddFeedbackActivity;
import com.luck.picture.lib.PictureExternalPreviewActivity;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.compress.Luban;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.DoubleUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lv on 17-9-7.
 */

public class PicUtil {
    public static void single(Activity activity) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)
                .minimumCompressSize(200)
                .imageSpanCount(3)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void single(Activity activity, boolean isCamera) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)
                .isCamera(isCamera)
                .minimumCompressSize(200)
                .imageSpanCount(3)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void singleSqare(Activity activity) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)
                .enableCrop(true)
                .minimumCompressSize(200)
                .withAspectRatio(500, 500)
                .freeStyleCropEnabled(false)
                .showCropFrame(true)
                .rotateEnabled(true) // 裁剪是否可旋转图片 true or false
                .scaleEnabled(true)// 裁剪
                .imageSpanCount(3)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void cut(Activity activity, int width, int height) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)
                .imageSpanCount(3)
                .enableCrop(true)
                .minimumCompressSize(200)
                .freeStyleCropEnabled(false)
                .showCropFrame(true)
                .withAspectRatio(width, height)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void cut(Activity activity, int width, int height, int num) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.MULTIPLE)
                .compress(true)
                .maxSelectNum(num)
                .imageSpanCount(3)
                .minimumCompressSize(200)
                .enableCrop(true)
                .freeStyleCropEnabled(false)
                .showCropFrame(true)
                .withAspectRatio(width, height)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void multi(Activity activity, List<LocalMedia> selectes) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .compress(true)
                .maxSelectNum(9)
                .imageSpanCount(3)
                .minimumCompressSize(200)
                .compress(true)
                .selectionMedia(selectes)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static void preview(Activity activity, int pos, List<LocalMedia> selectes) {
        PictureSelector.create(activity).externalPicturePreview(pos, selectes);
    }

    public static void previewSingle(Activity activity, LocalMedia localMedia) {
        ArrayList<LocalMedia> localMedias = new ArrayList<>();
        localMedias.add(localMedia);
        PictureSelector.create(activity).externalPicturePreview(0, localMedias);
    }

    public static void previewMy(Activity activity, int pos, List<LocalMedia> selectes, String from, String source) {
        if (!DoubleUtils.isFastDoubleClick()) {
            Intent intent = new Intent(activity, PicPreviewActivity.class);
            intent.putExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (Serializable) selectes);
            intent.putExtra(PictureConfig.EXTRA_POSITION, pos);
            intent.putExtra("from", from);
            intent.putExtra("source", source);
            activity.startActivity(intent);
            activity.overridePendingTransition(com.luck.picture.lib.R.anim.a5, 0);
        }
    }

    public static void camera(Activity activity) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .compress(true)
                .minimumCompressSize(200)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public static LocalMedia localMedia(String path) {
        return new LocalMedia(path, 0, PictureMimeType.ofImage(), PictureConfig.IMAGE);
    }
}
